﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemotingGraphClient.cs" company="">
//   
// </copyright>
// <summary>
//   The remoting graph client.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using Systemathics.FrameWork.Interfaces;

namespace Systemathics.FrameWork
{
    [Serializable]
    public sealed class RemotingGraphClient
    {
        private readonly IGraph m_IGraph;

        public RemotingGraphClient(String serverName, Object strategyIdORSerieName)
        {
            var m_ipc = new IpcClientChannel();

            if (m_ipc == null)
                ChannelServices.RegisterChannel(m_ipc, false);

            var portName = strategyIdORSerieName + ".rem";
            string adress = "ipc://" + serverName + "/" + portName;
            m_IGraph = (IGraph)Activator.GetObject(typeof(IGraph), adress);
        }

        public void Draw(GraphEventArgs e)
        {
            try
            {
                m_IGraph.Draw(e);
            } 
            catch (Exception exception)
            {
            }
        }
        public void DrawHistory(GraphEventArgs e)
        {
            try
            {
                m_IGraph.DrawHidtory(e);
            }
            catch (Exception exception)
            {
            }
        }
    }
}